package com.cloud.demo.models.sys.controller;

import com.cloud.demo.common.enums.ResultEnum;
import com.cloud.demo.common.web.domain.respomse.Result;
import com.cloud.demo.models.sys.domain.SysRole;
import com.cloud.demo.models.sys.qo.SysRoleQuery;
import com.cloud.demo.models.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 用户控制层
*/
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/list")
    public Result list(Model model, @ModelAttribute("qo") SysRoleQuery qo){
        IPage<SysRole> page = sysRoleService.queryPage(qo);
        model.addAttribute("page", page);
        return Result.build(ResultEnum.SUCCESS,page);
    }

    @RequestMapping("/get")
    @ResponseBody
    public Object get(Long id){
        return Result.build(ResultEnum.SUCCESS,sysRoleService.getById(id));
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(SysRole sysRole){
        sysRoleService.saveOrUpdate(sysRole);
        return Result.build(ResultEnum.SUCCESS,null);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        sysRoleService.removeById(id);
        return Result.build(ResultEnum.SUCCESS,null);
    }
}
